package by.grsu.hdm.devices;

import java.util.ArrayList;
import by.grsu.hdm.model.RCSignalAvailableEventListener;
import by.grsu.hdm.model.RCSignal;
import by.grsu.hdm.model.RCSignalAvailableEvent;

public class RemoteControl {
	private ArrayList<RCSignalAvailableEventListener> listeners = new ArrayList<RCSignalAvailableEventListener>();
	
	public RemoteControl() {}

	private void sendRCSignal(RCSignal rcSignal){
		RCSignalAvailableEvent event = new RCSignalAvailableEvent(this, rcSignal);
		for (RCSignalAvailableEventListener listener : listeners) {
			listener.rcSignalAvailableEvent(event);
		}
	}
	
	public void playPause() {
		sendRCSignal(RCSignal.PlayPause);
	}
	
	public void playNext() {
		sendRCSignal(RCSignal.PlayNext);
	}
	
	public void playPrevious() {
		sendRCSignal(RCSignal.PlayPrevious);
	}
	
	public void addRCSignalAvailableEventListener(RCSignalAvailableEventListener listener){
		listeners.add(listener);
    }
	
	public RCSignalAvailableEventListener[] getRCSignalAvailableEventListeners(){
		return listeners.toArray(new RCSignalAvailableEventListener[listeners.size()]);
	}
	
	public void removeRCSignalAvailableEventListener(RCSignalAvailableEventListener listener){
		listeners.remove(listener);
	}
}
